package com.servlet;

import com.servlet.bean.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @Title: GetSession
 * @Description:
 * @Auther: py
 * @Version: 1.0
 * @create 2023/12/25 13:34
 */
@WebServlet("/getsession")
public class GetSession extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
          // 获取session
        HttpSession session = req.getSession();
        // 获取sessionid
        String sessionId = session.getId();
        System.out.println(sessionId);

        User user = (User)session.getAttribute("user");
        System.out.println(user);

        resp.getWriter().write("success!");


    }
}
